Add options to enable/disable docs and demos

Originally written by Anthony Viallard
<viallard@syscom-instruments.com>.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
[Vincent: adapt patch to 5.0.5 version]
Signed-off-by: Vicente Olivert Riera <Vincent.Riera@imgtec.com>
[Michael: adapt patch to 5.4.0 version]
Signed-off-by: Michael Fischer <mf@go-sys.de>

diff -Naur a/configure.ac b/configure.ac
--- a/configure.ac	2020-07-12 02:29:47.000000000 +0200
+++ b/configure.ac	2020-08-06 14:21:17.918756893 +0200
@@ -713,6 +713,17 @@
                [ Define if you want to read .gnuplot from current directory (SECURITY RISK!).])
 fi
 
+dnl Whether we want to build the doc files
+dnl Does nothing here, is passed on to the doc subdir
+AC_ARG_ENABLE(doc,dnl
+[  --disable-doc    do not build doc files])
+
+dnl Whether we want to build the demo files
+dnl Does nothing here, is passed on to the demo subdir
+AC_ARG_ENABLE(demo,dnl
+[  --disable-demo    do not build demo files])
+
+
 dnl Sort help/subtopic tables by row or column
 AC_ARG_WITH(row-help,dnl
 [  --with-row-help         format help and subtopic tables by row (default)
@@ -1095,6 +1106,24 @@
   AC_DEFINE_UNQUOTED([DIST_CONTACT],["$DIST_CONTACT"],[Contact address for modified and binary distributed gnuplot versions])
 fi
 
+dnl build doc files
+if test "$enable_doc" != no; then
+  AC_CONFIG_SUBDIRS(docs)
+  DOCSUBDIR=docs
+else
+  DOCSUBDIR=
+fi
+AC_SUBST(DOCSUBDIR)
+
+dnl build demo files
+if test "$enable_demo" != no; then
+  AC_CONFIG_SUBDIRS(demo)
+  DEMOSUBDIR=demo
+else
+  DEMOSUBDIR=
+fi
+AC_SUBST(DEMOSUBDIR)
+
 dnl Substitute variables
 AC_SUBST(PACKAGE)
 AC_SUBST(VERSION_MAJOR)
diff -Naur a/Makefile.am b/Makefile.am
--- a/Makefile.am	2020-03-31 19:28:16.000000000 +0200
+++ b/Makefile.am	2020-08-06 14:34:12.995097799 +0200
@@ -1,7 +1,7 @@
 ## Process this file with automake to produce Makefile.in -*-Makefile-*-
 AUTOMAKE_OPTIONS = foreign
 
-SUBDIRS = config m4 term src docs man demo share
+SUBDIRS = config m4 term src $(DOCSUBDIR) man $(DEMOSUBDIR) share
 
 EXTRA_DIST = BUGS Copyright FAQ.pdf INSTALL INSTALL.gnu \
 PATCHLEVEL PGPKEYS README RELEASE_NOTES \
